<?php
include_once "objs/Comments.php";
include_once "objs/News.php";
include_once "models/CommentDao.php";
include_once "models/NewsDao.php";
include_once "models/Util.php";
include_once "models/MySqlDataAccessHelper.php";

MySqlDataAccessHelper::open();

$comments = CommentDao::getComments();
$mostNews = NewsDao::getCommonNews(10);

MySqlDataAccessHelper::close();
?>
<div id="zt-content-right">
    <?php if(count($comments) > 0){ ?>
    <div class="module-color zt-mod-br">
        <div class="zt-mod-bl">
            <div class="zt-mod-tr">
                <div class="zt-mod-tl clearfix">
                    <h3>
                        <span>Ý kiến khách hàng</span>
                    </h3>
                    <div class="mod-content">
                        <div class="latestnews" style="width: 100%">
                            <div class="latestnewsitems" style="width: 100%">
                                <!-- Begin y kien kh item-->
                                <?php foreach($comments as $cmt){ 
                                    $pos = mb_strpos($cmt->getContent(), ' ', 50);
                                $shortCmt = mb_substr($cmt->getContent(), 0,$pos );
                                
?>
                                <div class="latestnewsitems-inner">
                                    <a
                                        href="ykienkhachhang.php?id=<?php echo $cmt->getId(); ?>"
                                        class="latestnews-testimonial"><img
                                            src="<?php echo $cmt->getImg(); ?>"
                                            alt="<?php echo $cmt->getName(); ?>" style="height: 50px; width: 70px;" border="0"/></a>
                                    <div class="hidden">
                                        <h4>
                                            <a
                                                href="ykienkhachhang.php?id=<?php echo $cmt->getId(); ?>"
                                                class="latestnews-testimonial"><?php echo $cmt->getName(); ?></a>
                                        </h4>

                                        <span style="margin: 0;"><?php echo $shortCmt; ?>... </span>

                                    </div>
                                </div>
                                <?php } ?>
                            </div>
                            <!-- end y kien kh item-->

                        </div>
                        <div style="display: none;">
                            <a href="http://www.joomlavision.com/"
                               title="Joomla Templates">Joomla Templates</a> and
                            Joomla Extensions by JoomlaVision.Com
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <?php } ?>
    <?php if(count($mostNews) > 0){ ?>
    <div class="module-color zt-mod-br">
        <div class="zt-mod-bl">
            <div class="zt-mod-tr">
                <div class="zt-mod-tl clearfix">
                    <h3>
                        <span>Bài xem nhiều nhất</span>
                    </h3>
                    <div class="mod-content">
                        <script type="text/javascript">
                            var ajaxUrl = "http://www.sait.asia/modules/mod_zt_accordion_ajax/ajax.php";
                            var mod_id = 164;
                            var readMoreText = "Xem tiếp";
                            var jvStyle = "jv_default_accordion";
                        </script>



                        <div id="abc_bca" style="display: none;">
                            <a href="http://www.zootemplate.com/"
                               title="Joomla Templates">Joomla Templates</a> and
                            Joomla Extensions by ZooTemplate.Com
                        </div>
                        <div id="jv_accordion164" class="jv_default_accordion">
                            <!-- begin bai xem nhiu nhat item-->
                            <?php 
                            if(count($mostNews) > 0){ 
                            $titleLength = 50;
                            $firstNew = $mostNews[0];
                            $shortName = $firstNew->getName();
                            if(strlen($shortName) >= $titleLength){
                                $tempPos = mb_strpos($shortName, ' ', $titleLength - 10);
                                $shortName = mb_substr($firstNew->getName(), 0, $tempPos);
                            }
                            $shortGoodNew = Util::getShortContent($firstNew->getContent(), ' ', 130);
                            
?>
                            <!-- begin bai xem nhiu nhat first item-->
                            <div class="jv_accordion">
                                <div class="jv_accordion_item"
                                     onclick="newsclick('newItem_<?php echo $firstNew->getId(); ?>');" style="cursor: pointer; cursor: hand;" >
                                    <a class="toggler atStart164"><span><?php echo $shortName; ?> </span></a>
                                    <div id="newItem_<?php echo $firstNew->getId(); ?>"
                                        style="margin: 0px; position: static; overflow: hidden; height: 240px; ">
                                        <div style="margin: 0px; overflow: hidden;"
                                             class="element atStart164" id="content164_<?php echo $firstNew->getId(); ?>">
                                            <div class="answer_text">&nbsp;</div>
                                            <div class="answer_content">
                                                <?php if(strlen($firstNew->getThumbnail()) > 0){ ?>
                                                <a href="tintuc.php?id=<?php echo $firstNew->getId(); ?>">
                                            <img class="jv_thumb_content" style="height: 100px; width: 220px;"
                                                 src="<?php echo $firstNew->getThumbnail(); ?>"/></a>
                                            <?php } ?>
                                             <?php echo $shortGoodNew; ?>... </div>
                                            <div class="readmore"> <a
                                                    href="tintuc.php?id=<?php echo $firstNew->getId(); ?>">Xem
                                                    tiếp</a> </div>
                                            <br clear="all" />
                                        </div>
                                    </div>
                                </div>
                            </div>
                            
                            <!-- end bai xem nhiu nhat first item-->
                            <!-- begin bai xem nhiu nhat second item-->
                            <?php 
                            for($iMostNew = 1; $iMostNew < count($mostNews); $iMostNew++){ 
                            $mostNew = $mostNews[$iMostNew];
                            $shortName = $mostNew->getName();
                            if(strlen($shortName) >= $titleLength){
                                $tempPos = mb_strpos($shortName, ' ', $titleLength - 10);
                                $shortName = mb_substr($mostNew->getName(), 0, $tempPos);
                            }
                            $shortGoodNew = Util::getShortContent($mostNew->getContent(), ' ', 130);
                            
?>
                            <div class="jv_accordion">
                                <div class="jv_accordion_item"
                                     onclick="newsclick('newItem_<?php echo $mostNew->getId(); ?>');" style="cursor: pointer; cursor: hand;">
                                    <a class="toggler atStart164"><span><?php echo $shortName; ?></span></a>
                                </div>
                                <div id="newItem_<?php echo $mostNew->getId(); ?>"
                                    style="margin: 0px; position: static; overflow: hidden; height: 240px; display: none;">
                                    <div
                                        style="margin: 0px 0px 0px; overflow: hidden;"
                                        class="element atStart164" id="content164_<?php echo $mostNew->getId(); ?>">
                                        <div class="answer_text">&nbsp;</div>
                                        <div class="answer_content" >
                                            <?php if(strlen($mostNew->getThumbnail()) > 0){ ?>
                                            <a href="tintuc.php?id=<?php echo $mostNew->getId(); ?>">
                                                <?php if(strlen($mostNew->getThumbnail()) > 0){ ?>
                                            <img class="jv_thumb_content" style="height: 100px; width: 220px;"
                                                 src="<?php echo $mostNew->getThumbnail(); ?>"/>
                                                <?php } ?>
                                            </a>
                                            <?php } ?>
                                                     <?php echo $shortGoodNew; ?>
                                        </div>
                                        <div class="readmore">
                                            <a
                                                href="tintuc.php?id=<?php echo $mostNew->getId(); ?>">Xem
                                                tiếp</a>
                                        </div>
                                        <br clear="all">
                                    </div>
                                </div>
                            </div>
                            <?php }
                            }else{
                                echo 'Hiện chưa có bài viết nào!';
                            } ?>
                            
                            <script type="text/javascript">
                                function newsclick(newid){
                                    var style = 'background-color:#000';
                                    //$('#newItem_1').attr("style", style);
                                    $('#'+newid).slideToggle(500);
                                }
                            </script>
                            <!-- begin bai xem nhiu nhat second item-->
                            <!-- end bai xem nhiu nhat item-->
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <?php } ?>

</div>
